<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Untitled Page</title>
	<script type="text/javascript">

function InsertHtml( html )
{
	// Get the first available range.
	var oRange = window.getSelection().getRangeAt(0) ;

	// Create a fragment with the input HTML.
	var oFragment = oRange.createContextualFragment( html ) ;

	// Insert the fragment in the range.
	oRange.insertNode(oFragment) ;
}

	</script>
</head>
<body>
	Selection part of this text or just click on it and hit the "Insert HTML" button.
	<br />
	<input type="button" value="Insert HTML" onmousedown="InsertHtml('-- Inserted HTML--');" />
	<br />
	<br />
	It must work on both cases, selecting text and clicking inside it (positioning a
	empty selection inside it). Opera is throwing different erros for each case. For
	FCKeditor, the "Type mismatch (usually a non-object value used where an object is
	required)" error is more important.
</body>
</html>
